jQuery(document).ready(function() {
	//创建JQGRID表格
	var grid = $("#table1").ligerGrid({
        columns: [
                  { display: '登录名', name: 'name', align: 'left', width: 120 },
                  { display: '姓名', name: 'realname', width: 220, align: 'left' },
                  { display: '创建时间', name: 'createdate', width: 220, align: 'left',
                	  render: function (item){
                		  var cdate=new Date(item.createdate);
                		  return formatDate(cdate,"yyyy-MM-dd HH:mm:ss")
                	  } 
                  },
                  { display: '状态', name: 'enabled', width: 170, align: 'left' ,
                	  render: function (item){
	                      if (parseInt(item.enabled) == 0) {
	                    	  return '冻结';
	                      }else if (parseInt(item.enabled) == 1) {
	                    	  return '激活';
	                      }
	                      return item.enabled;
                      } },
                      { display: '', name: 'id', width: 170, align: 'left' ,
                    	  render: function (item){
    	                        return "<a href='javascript:showUser(" + item.id + ")'>角色管理</a> "; 
                          } }
                      ],  usePager: true,pageSize:30,
                      url : sys_context+"/security/user/list.do",
                      width: '100%', height: '98%', checkbox: true,rownumbers:true,           
                      onDblClickRow : function (data, rowindex, rowobj){
                          edit(data);
                       }
                  });
	$("#pageloading").hide();
	
	
});
var showUser = function(rowid){		
	var dialogUrl = "/security/user/userRole.do?userId=" + rowid;
	ShowIframeDialogMax("operate","编辑用户角色",dialogUrl,750,500);
}	
//添加
function add(){
	var url = "/security/user/operate/add/0.do";
	
	ShowIframeDialog("operate","添加用户",url,650,300);
}
//编辑
function edit(data){
	var url = "/security/user/operate/edit/"+data.id+".do";
	ShowIframeDialog("operate","修改用户",url,650,300);
}

function del(){
	var manager = $("#table1").ligerGetGridManager(); 
	var rows = manager.getCheckedRows(); 
	
	if (rows.length==0){
		$.dialog.alert('Please select a record');
		return;
	}
    
    var ids = "";
	for(var i = 0;i < rows.length ;i ++) {
	 	if(i!=0){
	 		ids+=",";
	 	}
	 	//获得行数据
	 	ids += rows[i].id;					 	   
	}
	
	getDG().dialog({content: "请确定选择删除数据(Yes或者No)!",width: 250,lock: true,max: false,min: false,
		title:'Confirm Infor',
		button: [
		         {
		             name: 'Yes',
		             callback: function(){
			            $.ajax({
			           	      url: sys_context+"/security/user/delete.do",
			           	      global: false,
			           	      type: "POST",
			           	      dataType: "json",
			           	      data: ({ids : ids}),		     
			           	      success: function(msg){	
			           	    	manager.removeRange(rows);
			           	    	  $.dialog.alert(msg.infor);  		    	
			           	      }
			           	   }
			           	);
		             }
		         },
		         {
		        	   name: 'No',
			           focus: true
		         }             
		     ]
	}).zindex();
	
	
}